package com.baway.home.model

import com.baway.common.entity.BaseResponse
import com.baway.common.entity.NoticeEntity
import com.baway.db.RoomDBUtils
import com.baway.db.entity.UserInfoEntity
import com.baway.home.api.HomeApiServer
import com.blankj.utilcode.util.NetworkUtils
import javax.inject.Inject

/**
 * Author: Jason Zhang
 * Date: 2025/8/18
 * Desc: 首页仓库层
 */
class HomeRepository @Inject constructor(private val apiServer: HomeApiServer){

    private val mUserInfoDao = RoomDBUtils.getDataBase().getUserInfoDao()

    suspend fun loadNoticeData(pageIndex: Int, pageSize: Int): BaseResponse<List<NoticeEntity>>{
        //有网则请求接口
        return if (NetworkUtils.isAvailable()){
            apiServer.loadNoticeData(pageIndex, pageSize)
        } else {
            BaseResponse(400, emptyList(), "当前没有网络！")
        }
    }

    suspend fun queryUserInfo(userId: Int): UserInfoEntity =  mUserInfoDao.queryUserInfoById(userId)


}